package com.gougou.manager.web.controller;

import com.gougou.pic.entity.PicUploadResult;
import com.gougou.pic.service.PicUploadService;
import com.gougou.pic.service.TxyunPicUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/pic")
public class PicUploadController {

    @Autowired
    private PicUploadService picUploadService;
    @Autowired
    private TxyunPicUploadService txyunPicUploadService;

    /*************************
     *
     * 商品上传图片方法
     *
     * @param uploadFile
     * @return
     * ******************************
     */
    @RequestMapping(value = "/upload/item",method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public PicUploadResult uploaditem(@RequestParam("uploadFile") MultipartFile uploadFile, HttpServletResponse response){
        // 要上传的文件要放在根目录的哪个位置
        String localPath ="/item";
        //写入到磁盘
//       return  picUploadService.fileUpload(uploadFile,localPath);
        //写入服务器
        return  txyunPicUploadService.fileUpload(uploadFile,localPath);
    }

}
